import React, { useReducer, useEffect } from "react";
import "./login.css"
import { initState, reducer, actions } from "./login";
import { reqLogin } from "../../request/api"
const Login = (props) => {
    const [state, dispatch] = useReducer(reducer, initState);
    //进来页面
    useEffect(() => {
        
    }, []);
    let req=()=>{
        // 注册请求
        reqLogin(state.user).then(res => {
            if (res.data.code === 200) {
                dispatch(actions.changeInfo(res.data.list));
                //跳转页面
                props.history.push("/index/home")
            }
        })
    }
    return (
        <div className="login">
            <ul>
                <li>账号：<input type="text" value={state.phone} onChange={(e) => dispatch(actions.changeUser("phone", e.target.value))} /></li>
                <li>密码：<input type="text" value={state.password} onChange={(e) => dispatch(actions.changeUser("password", e.target.value))} /></li>
            </ul>
            <input type="button" value="登录" onClick={() => req()} />
        </div>
    );
};

export default Login;
